﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Configuration;


namespace DALFactory
{
    public class DataAccess
    {
        //使用反射工厂模式

        //从web/Web.config配置文件里取出“WebDAL”这个变量，确定当前使用的数据库层
        //（我们用的是DAL这个数据库层，如果需要添加其他数据库层，只需修改web/Web.config配置文件并添加一个数据库操作类，
        //例如OracleDAL即可实现数据库层的改变，无需再修改这里的内容）
        private static readonly string path = ConfigurationManager.AppSettings["WebDAL"];

        private DataAccess()
        {
        }

        //添加其他表的Factory请在这里添加

        public static IDAL.IMessage CreateMessage()
        {
            //获得Message的DAL类（在我们的项目里，path指向DAL这个工程）
            string className = path + ".Message";

            return (IDAL.IMessage)Assembly.Load(path).CreateInstance(className);
        }

        //public static IDAL.IUserInfo CreateUserInfo()
        //{
        //    //获得Message的DAL类（在我们的项目里，path指向DAL这个工程）
        //    string className = path + ".UserInfo";

        //    return (IDAL.IMessage)Assembly.Load(path).CreateInstance(className);
        //}
        public static IDAL.IAdminUser CetUser()
        {
            string className = path + ".AdminUser";
            return (IDAL.IAdminUser)Assembly.Load(path).CreateInstance(className);
        }

        public static IDAL.IAdminVideo CetVideo()
        {
            string className = path + ".AdminVideo";
            return (IDAL.IAdminVideo)Assembly.Load(path).CreateInstance(className);
        }

        public static IDAL.IAdminAdmin CetAdmin()
        {
            string className = path + ".AdminAdmin";
            return (IDAL.IAdminAdmin)Assembly.Load(path).CreateInstance(className);
        }

        public static IDAL.UserinfoIDAL getUserinfoIDAL()
        {
            string className = path + ".UserinfoDAL";
            //利用反射技术，动态加载指定类型
            return (IDAL.UserinfoIDAL)Assembly.Load(path).CreateInstance(className);
        }


        public static IDAL.IAlbum GetAlbum()
        {
            string className = path + ".Album";
            return (IDAL.IAlbum)Assembly.Load(path).CreateInstance(className);
        }

        public static IDAL.IUserInfo UpdateUser()
        {
            string className = path + ".UserInfoEdit";
            return (IDAL.IUserInfo)Assembly.Load(path).CreateInstance(className);
        }

        public static IDAL.IVideo GetVideo()
        {
            string className = path + ".Video";
            return (IDAL.IVideo)Assembly.Load(path).CreateInstance(className);
        }

        public static IDAL.IVideoInVideoPage GetVideoInVideoPage()
        {
            string className = path + ".VideoInVideoPage";
            return (IDAL.IVideoInVideoPage)Assembly.Load(path).CreateInstance(className);
        }

        public static IDAL.Video_albumIDAL getVideo_albumIDAL()
        {
            string className = path + ".Video_albumDAL";
            //利用反射技术，动态加载指定类型
            return (IDAL.Video_albumIDAL)Assembly.Load("Face.Dll").CreateInstance("Face.Dll.Video_albumDAL");
        }


        public static IDAL.PictureIDAL getPictureIDAL()
        {
            string className = path + ".PictureDAL";
            //利用反射技术，动态加载指定类型
            return (IDAL.PictureIDAL)Assembly.Load(path).CreateInstance(className);
        }
    }
}
